package my_account;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Address_book_shipping_positive extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

    @Test
  public void testUntitled6() throws Exception {
	/*driver.get(baseUrl);
    driver.findElement(By.linkText("My Account")).click();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys("qatestingtestqa@gmail.com");
    driver.findElement(By.id("pass")).clear();
    driver.findElement(By.id("pass")).sendKeys("qwerty");
    driver.findElement(By.id("send2")).click();*/
    	driver.get(baseUrl + "/customer/account/");
    driver.findElement(By.linkText("Address Book")).click();
    driver.findElement(By.linkText("Change Shipping Address")).click();
    new Select(driver.findElement(By.id("region_id"))).selectByVisibleText("New Mexico");
    driver.findElement(By.cssSelector("div.buttons-set > button.button")).click();
    try {
      assertEquals("The address has been saved.", driver.findElement(By.cssSelector("li > span")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    try {
      assertEquals("test test\n 5 AV\n new york, New Mexico, 120000\n United States\n T: 876456456", driver.findElement(By.xpath("//li[2]/address")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    driver.findElement(By.linkText("Change Shipping Address")).click();
    new Select(driver.findElement(By.id("region_id"))).selectByVisibleText("New York");
    driver.findElement(By.cssSelector("div.buttons-set > button.button")).click();
    try {
      assertEquals("The address has been saved.", driver.findElement(By.cssSelector("li > span")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
    try {
      assertEquals("test test\n 5 AV\n new york, New York, 120000\n United States\n T: 876456456", driver.findElement(By.xpath("//li[2]/address")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
  }

   private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  
  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}
